import { createSlice } from '@reduxjs/toolkit'

export const commonDataSlice = createSlice({
    name: 'commonData',
    initialState: {
        userInfo: {},
        sysInfo: {},
        lg_ic: '',
        token: '',
        type: '', //页面路径
        baseAddr: '', //基础平台地址
        advanced: 0, //1 高级管理员权限
    },
    reducers: {
        setType: (state, action) => {  //每次进入存入全局token
            state.type = action.payload
        },
        setUserInfo: (state, action) => {
            state.userInfo = Object.assign({}, state.userInfo, action.payload)
        },
        setSysInfo: (state, action) => {
            state.sysInfo = Object.assign({}, state.sysInfo, action.payload)
        },
        setToken: (state, action) => {  //每次进入存入全局token
            state.token = action.payload
        },
        setIdentityCode: (state, action) => {  //每次进入存入全局token
            state.lg_ic = action.payload
        },
        setAdvanced: (state, action) => {  //每次进入存入全局token
            state.advanced = action.payload
        },
    },
})

export const {
    setType,
    setUserInfo,
    setSysInfo,
    setToken,
    setIdentityCode,
    setAdvanced
} = commonDataSlice.actions

export default commonDataSlice.reducer